<?php
/**
 * Created by PhpStorm.
 * User: fengke
 * Date: 2018/12/6
 * Time: 14:27
 */

namespace app\api\controller;


use app\common\controller\Api;
use app\common\library\book\dstiejuanCollect;

class Collection extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = '*';
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = '*';
    private $model;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\Collection();
    }

    /**
     * 函数用途描述: 获取所有书籍采集来源
     * @author: Feng_Ke
     * @date: 2018/12/6 14:29
     */
    public function getBookCategoryList(){
        $data = $this->model->getList(
            ['status' => ['<>',0]],
            'weigh asc',
            '',
            'id,collection_name,status'
        );
        $this->success('网站数据',$data);
    }

    /**
     * 函数用途描述: 搜索小说
     * @author: Feng_Ke
     * @date: 2018/12/10 15:30
     */
    public function GetBookList(){
        $param = $this->request->request();
        $searchkey = $param['searchkey'];
        $collect_id = $param['collect_id'];
        $collect = $this->model->getCollectById($collect_id);
        $rule = $collect['rules'];
        switch ($rule){
            case 'dstiejuan':
                $book = new dstiejuanCollect();
                $data = $book->getBookSearch($searchkey);
                break;
            case 2:
                break;
        }
        $this->success('查询数据',$data);
    }

    /**
     * 函数用途描述: 获取小说的章节列表
     * @author: Feng_Ke
     * @date: 2018/12/10 15:30
     */
    public function GetBookChapter(){
        //用户阅读数据的记录表
        $read_record_id = $this->request->request('id');
        if(!$read_record_id) $this->error('书籍信息必须传入');
        $readRecordModel = new \app\common\model\ReadRecord();
        $info = $readRecordModel->find($read_record_id);
        if(!$info) $this->error('无此信息');
        //得到查询的参数
        $collect_id = $info['collection_id'];
        $book_id = $info['book_id'];
        $collect = $this->model->getCollectById($collect_id);
        $rule = $collect['rules'];
        switch ($rule){
            case 'dstiejuan':
                $book = new dstiejuanCollect();
//                $data['info'] = $book->getBookInfo($book_id);
                $data['chapter'] = $book->getBookChapter($book_id);
                break;
            case 2:
                break;
        }
        $this->success('查询数据',$data);
    }

    /**
     * 函数用途描述: 获取小说的内容
     * @author: Feng_Ke
     * @date: 2018/12/10 15:31
     */
    public function GetBookContent(){

    }
}